<template>
  <div class="box">
    <TSComponentsChild ref="tsComponent"></TSComponentsChild>
    <button @click="printLogMsg">打印日志</button>
  </div>

</template>

<script setup lang="ts">
import TSComponentsChild from './components/TSComponentsChild.vue';
import { ref } from 'vue';

// typeof TSComponentsChild: 得到组件类型
// InstanceType: 得到实例类型
const tsComponent = ref<InstanceType<typeof TSComponentsChild> | null>(null)
const printLogMsg = () => {
  if(tsComponent.value) {
    tsComponent.value.logMessage()
  }
  // 等效写法
  // tsComponent.value?.logMessage()
}
</script>

<style scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 20px;
}
</style>
